<?php 
/**
 *  Create On 2015-01-01
 *  Author yiwei
 *  QQ:1006629314
 *  
 *  
 *  using 'wkhtmltopdf' to convert item to image or pdf
 *  @version :wkhtmltox-0.12.1.2_mingw-w64-cross-win64
 *   	
 *   
 *	$conv = new item2imgae();
 *	$conv->convert(934, 504, 0, 15000);
 **/

 class item2imgae{
 	//item sourse url
 	private $base_url; 
 	private $item_url;
 	
 	private $url;
 	//path for store imgae as jpg
 	private $filepath;
 	
 	public function __construct($base_url = null,$item_url = null,$filepath = null){
 		$this->base_url = 'http://localhost/xdfServer/clientapi.php/';
 		$this->item_url = 'item/getItemView/';
 		$this->url = $this->base_url.$this->item_url;
 		$this->filepath = '';
 	}
 	
 	/*
 	 * argvList:
 	 * item_id-题目id
 	 * width-打印宽度
 	 * type-显示题目内容或全部
 	 * delay-执行js的延时时间
 	 */
 	
 	public function convert($item_id,$width,$type,$delay){
 		//$filename = date('YmdHis').'.jpg';
 		$filename = $item_id.'.jpg';
 		$url = $this->url.'item_id/'.$item_id.'/type/'.$type.'/width/'.$width.'/mode/2';
 		$file = $this->filepath.$filename;
 		
 		
 		$cmd = 'wkhtmltoimage --width '.$width.' --javascript-delay '.$delay.' '.$url.' '.$file;
		echo $cmd;
		//exit;
 		passthru($cmd,$result);
 		if($result){
 			echo '失败';
 		}else{
 			echo '成功~';
 		}
 	} 	
 	
 }

	
?>